$(document).ready(function () {

    var iUserId   = addressUri.getParam('iUserId');
    var trackType = $('#trackType').val();
    $(function () { //加载时间轴
        $.ajax({
            url : baseUrl+'Tch/getTrace',
            dataType:'JSON',
            type:'Post',
            data:{'iUserId':iUserId,type:'1',trackType:trackType},
            success:function (data) {
                timeLine.loadTimeLine($('#timeWraper'),data['data'],'跟踪信息',data['showDelete'],data['showEdit']);
                $('.images').viewer();
            },
            error:function (result) {
                console.log(result);
            }
        });
    });

    $('#trackType').on('change',function () {
        trackType = $(this).val();
        $.ajax({
            url : baseUrl+'Tch/getTrace',
            dataType:'JSON',
            type:'Post',
            data:{'iUserId':iUserId,type:'1',trackType:trackType},
            success:function (data) {
                timeLine.loadTimeLine($('#timeWraper'),data['data'],'跟踪信息',data['showDelete'],data['showEdit']);
                $('.images').viewer();
            },
            error:function (result) {
                console.log(result);
            }
        });
    });





    //新建
    $('#new').click(function () {
        window.top.xhTop.showModal({
            title:'新建跟踪',
            content:'<iframe src="'+baseUrl+'Tch/trackForm?iUserId='+iUserId+'"  style="width: 100%;;border-style: none;padding: 0px;height:380px"  scrolling="yes"   ></iframe>',
            button:'提交',
            size:'lg',
            backClose:false
        });
    });

    $('#template').click(function () {
        window.top.xhTop.showModal({
            title:'原因跟踪模板',
            content:'<iframe src="'+baseUrl+'Tch/template"  style="width: 100%;;border-style: none;padding: 0px;height:350px"  scrolling="yes"   ></iframe>',
            size   :'lg',
            backClose:false
        });
    });



    //删除图片ajax
    $('#timeWraper').on('click','[id^=imageDelete_]',function () {
        var iTTchId=$(this).attr("id").split("_")[1];
        var rmId=$(this).attr('id').split('_')[2];
        myWindow.initPopUp({text: '你确定要删除这张图片吗?'},function () {
            $.ajax({
                url:baseUrl+'Tch/ajaxDelete',
                data:{'id':iTTchId,'rmId':rmId},
                dataType:'json',
                type:'post',
                success:function (data) {
                    //根据数据更新
                    // timeLine.loadTimeLine($('#timeWraper'),data['data'],'跟踪信息',data['showDelete'],data['showEdit']);
                    // $('.images').viewer();
                    location.reload();
                },
                error:function (result) {
                    console.log(result);
                }
            });
        });


    });


    //删除图片ajax
    $('#timeWraper').on('click','[id^=fileDelete_]',function () {
        var iTTchId=$(this).attr("id").split("_")[1];
        var rmId=$(this).attr('id').split('_')[2];
        myWindow.initPopUp({text: '你确定要删除这张图片吗?'},function () {
            $.ajax({
                url:baseUrl+'Tch/ajaxDelete/fileDelete',
                data:{'id':iTTchId,'rmId':rmId},
                dataType:'json',
                type:'post',
                success:function (data) {
                    //根据数据更新
                    // console.log(data);
                    // timeLine.loadTimeLine($('#timeWraper'),data['data'],'跟踪信息',data['showDelete'],data['showEdit']);
                    // $('.images').viewer();
                    location.reload();
                },
                error:function (result) {
                    console.log(result);
                }
            });
        });


    });

    //删除加载数据
    $('#timeWraper').on('click','[id^=delete_]',function () {
        var iTTchId=$(this).attr("id").split("delete_")[1];
        myWindow.initPopUp({},function () {
            $.ajax({
                url : baseUrl+'Tch/delTrack',
                data : {iTTchId:iTTchId},
                dataType : 'JSON',
                type : 'POST',
                success:function (data) {
                   location.reload();
                },
                error:function (result) {
                    console.log(result);
                }
            });
        });

    });

    $('#timeWraper').on('click','[id^=check_]',function () {
        var iTTchId=$(this).attr("id").split("check_")[1];
        window.top.xhTop.showModal({
            title:'审核跟踪信息',
            content:'<iframe src="'+baseUrl+'Tch/check?iTTchId='+iTTchId+'"  style="width: 100%;;border-style: none;padding: 0px;height:130px"  scrolling="yes"   ></iframe>',
            button:'审核通过',
            backClose:false,
        });

    });


    //编辑加载数据
    $('#timeWraper').on('click','[id^=edit_]',function () {
        var iTTchId=$(this).attr("id").split("edit_")[1];
        window.top.xhTop.showModal({
            title:'编辑跟踪',
            content:'<iframe src="'+baseUrl+'Tch/trackForm?iUserId='+iUserId+'&iTTchId='+iTTchId+'"  style="width: 100%;;border-style: none;padding: 0px;height:330px"  scrolling="yes"   ></iframe>',
            button:'提交',
            size:'lg',
            backClose:false,
        });


    });
});